<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class CollageGoods extends Model
{
    public function getCollageStartTimeAttr($value)
    {
        return date('Y-m-d H:i:s',$value);
    }

    public function getCollageEndTimeAttr($value)
    {
        return date('Y-m-d H:i:s',$value);
    }

    public function specGoods()
    {
        return $this->belongsTo('SpecGoods','goods_sku_id');
    }

    /**
     * @return CollageGoods[]|array|\think\Collection
     * 拼团商品列表
     */
    public function collageGoodsList()
    {
        $data = self::with(['SpecGoods.goods'])->where('collage_status',1)->select();
        return $data;
    }

    /**
     * @param $id
     * @return CollageGoods|array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 查询拼团商品信息
     */
    public function collageGoodsInfo($id)
    {
        return self::find($id);
    }
}
